package br.usp.pcs.lti.planning;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

import rddl.EvalException;
import rddl.RDDL.PVAR_INST_DEF;
import rddl.State;
import rddl.policy.Policy;
import rddl.solver.mdp.vi.VI;
import util.CString;
import dd.discrete.ADD;

/**
 * Representa uma política aprendida pelo SPUDD.
 * 
 * @author mlk
 * 
 */
public class SPUDDPolicy extends Policy implements Serializable {

    private static final long serialVersionUID = 1L;

    public ArrayList<CString> _alStateVars;
    public ADD _context;
    public HashMap<CString, Integer> _hmAct2Regr;

    private transient VI policy;

    public SPUDDPolicy(VI policy) {
        super();
        this._alStateVars = policy._alStateVars;
        this._context = policy._context;
        this._hmAct2Regr = policy._hmAct2Regr;
    }

    @Override
    public ArrayList<PVAR_INST_DEF> getActions(State s) throws EvalException {
        return this.getPolicy().getActions(s);
    }

    private VI getPolicy() {
        if (this.policy == null) {
            this.policy = new VI();
            this.policy._context = this._context;
            this.policy._hmAct2Regr = this._hmAct2Regr;
            this.policy._alStateVars = this._alStateVars;
        }
        return this.policy;
    }

}
